/***********************************************
 **** 版权声明处 **
 ****  为了方便阅读和维护，请严格遵守相关代码规范，谢谢   ****
 *******************************************/
package bpm.graphic
{
	/*******************************************
	 **** huangjixin,2012-10-16,上午9:02:01 **
	 **** 图形基类  **
	 *******************************************/
	import flash.events.Event;
	import flash.geom.Point;
	import flash.utils.getDefinitionByName;
	import flash.utils.getQualifiedClassName;
	
	import mx.core.ClassFactory;
	import mx.utils.ObjectUtil;
	import mx.utils.UIDUtil;
	
	import spark.components.Label;
	import spark.components.SkinnableContainer;
	import spark.components.supportClasses.SkinnableComponent;
	
	public class Node extends SkinnableContainer
	{
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		// private 类私有静态变量和静态常量声明处。（全部大写，使用下划线进行分割）
		// 例如：private static const EXAMPLE:String = "example";
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		// public 类公有静态变量和静态常量声明处。（全部大写，使用下划线进行分割）
		// 例如：public static const EXAMPLE:String = "example";
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		
		
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		// private 私有变量声明处，请以“_”开头定义变量
		// 例如：private var _example:String;
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		private var _isSelected:Boolean;
		
		private var _label:String;
		
		protected var labelChanged:Boolean;
		private var _labelEditable:Boolean;
		
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		// public 公有变量声明处
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		[SkinPart(required="false")]
		public var labelDisplay:Label;
		
		public var dymicPro:Point = new Point();
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		// 构造函数，初始化相关工作可以放在里面
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		public function Node()
		{
			super();
			
			_labelEditable = true;
			label		 = "Node";
			isSelected   = false;
		}//构造函数结束
		
		
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		// getter和setter函数
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		
		[Bindable]
		/**
		 *	表明该对象是否被选中 
		 */
		public function get isSelected():Boolean
		{
			return _isSelected;
		}
		
		/**
		 * @private
		 */
		public function set isSelected(value:Boolean):void
		{
			_isSelected = value;
			invalidateSkinState();
		}
		
		[Bindable(event="labelChange")]
		/**
		 *	显示文本 
		 */
		public function get label():String
		{
			return _label;
		}
		
		/**
		 *
		 * @private
		 */
		public function set label(value:String):void
		{
			if( _label !== value)
			{
				_label = value;
				dispatchEvent(new Event("labelChange"));
				labelChanged = true;
				invalidateProperties();
			}
		}
		
		[Bindable(event="labelEditableChange")]
		/**
		 * 文本是否可以编辑； 
		 * @return 
		 * 
		 */
		public function get labelEditable():Boolean
		{
			return _labelEditable;
		}
		
		public function set labelEditable(value:Boolean):void
		{
			if( _labelEditable !== value)
			{
				_labelEditable = value;
				dispatchEvent(new Event("labelEditableChange"));
			}
		}
		
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		// 相关事件响应函数和逻辑函数存放处
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		override protected function getCurrentSkinState():String
		{
			if (isSelected){
				return "selected";
			}else{
				return "normal";
			}
			
			return super.getCurrentSkinState();
		}
		
		public function clone():Node{
			var cloneObject:Object = ObjectUtil.getClassInfo(this);
			var properties:Array = cloneObject['properties'];
			var className:String=getQualifiedClassName(this);
			var ClassName:Class=getDefinitionByName(className) as Class;
			
			var classFactory:ClassFactory = new ClassFactory(ClassName);
			
			var node:Node = classFactory.newInstance();
			
			/*for each (var qName:QName in properties) 
			{
				var localName:Object = qName.localName;
				if(this.hasOwnProperty(localName)){
					
					if (qName.uri == ""){
						node[localName] = null;					
					}else{
						node[localName] = qName.uri;
					}
				}
			}*/
			
			var skinClass:* = this.getStyle("skinClass");
			node.setStyle("skinClass",this.getStyle("skinClass"));
			node.label = this.label;
			node.labelEditable = true;
			node.width = this.width;
			node.height = this.height;
			node.x = this.x;
			node.y = this.y;
			node.name = this.name;
			var dotIndex:int = className.lastIndexOf("::");
			if(dotIndex > 0){
				var name:String = className.substring(dotIndex+2, className.length);
				name = name.toLowerCase();
			}
			node.id = name+UIDUtil.createUID();
			return node;
		}
		
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		// override 覆盖函数
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		override protected function commitProperties():void{
			super.commitProperties();
			
			if(labelDisplay){
				if(labelChanged){
					labelChanged = false;
					labelDisplay.text = label;
				}
			}
		}
	}//类结束
}//包结束